@@ -1,5 +1,5 @@ |
||
1 | 1 |
module Agents |
2 |
- class DigestEmailAgent < Agent |
|
2 |
+ class EmailDigestAgent < Agent |
|
3 | 3 |
include EmailConcern |
4 | 4 |
|
5 | 5 |
default_schedule "5am" |
@@ -7,7 +7,7 @@ module Agents |
||
7 | 7 |
cannot_create_events! |
8 | 8 |
|
9 | 9 |
description <<-MD |
10 |
- The DigestEmailAgent collects any Events sent to it and sends them all via email when run. |
|
10 |
+ The EmailDigestAgent collects any Events sent to it and sends them all via email when run. |
|
11 | 11 |
The email will be sent to your account's address and will have a `subject` and an optional `headline` before |
12 | 12 |
listing the Events. If the Events' payloads contain a `message`, that will be highlighted, otherwise everything in |
13 | 13 |
their payloads will be shown. |
@@ -0,0 +1,21 @@ |
||
1 |
+class RenameDigestEmailToEmailDigest < ActiveRecord::Migration |
|
2 |
+ def up |
|
3 |
+ sql = <<-SQL |
|
4 |
+ UPDATE #{ActiveRecord::Base.connection.quote_table_name('agents')} |
|
5 |
+ SET #{ActiveRecord::Base.connection.quote_column_name('type')} = "Agents::EmailDigestAgent" |
|
6 |
+ WHERE #{ActiveRecord::Base.connection.quote_column_name('type')} = "Agents::DigestEmailAgent" |
|
7 |
+ SQL |
|
8 |
+ |
|
9 |
+ execute sql |
|
10 |
+ end |
|
11 |
+ |
|
12 |
+ def down |
|
13 |
+ sql = <<-SQL |
|
14 |
+ UPDATE #{ActiveRecord::Base.connection.quote_table_name('agents')} |
|
15 |
+ SET #{ActiveRecord::Base.connection.quote_column_name('type')} = "Agents::DigestEmailAgent" |
|
16 |
+ WHERE #{ActiveRecord::Base.connection.quote_column_name('type')} = "Agents::EmailDigestAgent" |
|
17 |
+ SQL |
|
18 |
+ |
|
19 |
+ execute sql |
|
20 |
+ end |
|
21 |
+end |
@@ -69,7 +69,7 @@ unless user.agents.where(:name => "Rain Notifier").exists? |
||
69 | 69 |
end |
70 | 70 |
|
71 | 71 |
unless user.agents.where(:name => "Morning Digest").exists? |
72 |
- Agent.build_for_type("Agents::DigestEmailAgent", user, |
|
72 |
+ Agent.build_for_type("Agents::EmailDigestAgent", user, |
|
73 | 73 |
:name => "Morning Digest", |
74 | 74 |
:schedule => "6am", |
75 | 75 |
:options => { 'subject' => "Your Morning Digest", 'expected_receive_period_in_days' => "30" }, |
@@ -77,7 +77,7 @@ unless user.agents.where(:name => "Morning Digest").exists? |
||
77 | 77 |
end |
78 | 78 |
|
79 | 79 |
unless user.agents.where(:name => "Afternoon Digest").exists? |
80 |
- Agent.build_for_type("Agents::DigestEmailAgent", user, |
|
80 |
+ Agent.build_for_type("Agents::EmailDigestAgent", user, |
|
81 | 81 |
:name => "Afternoon Digest", |
82 | 82 |
:schedule => "5pm", |
83 | 83 |
:options => { 'subject' => "Your Afternoon Digest", 'expected_receive_period_in_days' => "7" }, |
@@ -1,12 +1,12 @@ |
||
1 | 1 |
require 'spec_helper' |
2 | 2 |
|
3 |
-describe Agents::DigestEmailAgent do |
|
3 |
+describe Agents::EmailDigestAgent do |
|
4 | 4 |
def get_message_part(mail, content_type) |
5 | 5 |
mail.body.parts.find { |p| p.content_type.match content_type }.body.raw_source |
6 | 6 |
end |
7 | 7 |
|
8 | 8 |
before do |
9 |
- @checker = Agents::DigestEmailAgent.new(:name => "something", :options => { :expected_receive_period_in_days => 2, :subject => "something interesting" }) |
|
9 |
+ @checker = Agents::EmailDigestAgent.new(:name => "something", :options => { :expected_receive_period_in_days => 2, :subject => "something interesting" }) |
|
10 | 10 |
@checker.user = users(:bob) |
11 | 11 |
@checker.save! |
12 | 12 |
end |
@@ -27,14 +27,14 @@ describe Agents::DigestEmailAgent do |
||
27 | 27 |
event2.payload = { :data => "Something else you should know about" } |
28 | 28 |
event2.save! |
29 | 29 |
|
30 |
- Agents::DigestEmailAgent.async_receive(@checker.id, [event1.id, event2.id]) |
|
30 |
+ Agents::EmailDigestAgent.async_receive(@checker.id, [event1.id, event2.id]) |
|
31 | 31 |
@checker.reload.memory[:queue].should == [{ 'data' => "Something you should know about" }, { 'data' => "Something else you should know about" }] |
32 | 32 |
end |
33 | 33 |
end |
34 | 34 |
|
35 | 35 |
describe "#check" do |
36 | 36 |
it "should send an email" do |
37 |
- Agents::DigestEmailAgent.async_check(@checker.id) |
|
37 |
+ Agents::EmailDigestAgent.async_check(@checker.id) |
|
38 | 38 |
ActionMailer::Base.deliveries.should == [] |
39 | 39 |
|
40 | 40 |
@checker.memory[:queue] = [{ :data => "Something you should know about" }, |
@@ -44,7 +44,7 @@ describe Agents::DigestEmailAgent do |
||
44 | 44 |
@checker.memory[:events] = [1,2,3,4] |
45 | 45 |
@checker.save! |
46 | 46 |
|
47 |
- Agents::DigestEmailAgent.async_check(@checker.id) |
|
47 |
+ Agents::EmailDigestAgent.async_check(@checker.id) |
|
48 | 48 |
ActionMailer::Base.deliveries.last.to.should == ["bob@example.com"] |
49 | 49 |
ActionMailer::Base.deliveries.last.subject.should == "something interesting" |
50 | 50 |
get_message_part(ActionMailer::Base.deliveries.last, /plain/).strip.should == "Event\n data: Something you should know about\n\nFoo\n bar: 2\n url: http://google.com\n\nhi\n woah: there\n\nEvent\n test: 2" |
@@ -61,7 +61,7 @@ describe Agents::DigestEmailAgent do |
||
61 | 61 |
Agent.receive! |
62 | 62 |
@checker.reload.memory[:queue].should_not be_empty |
63 | 63 |
|
64 |
- Agents::DigestEmailAgent.async_check(@checker.id) |
|
64 |
+ Agents::EmailDigestAgent.async_check(@checker.id) |
|
65 | 65 |
|
66 | 66 |
plain_email_text = get_message_part(ActionMailer::Base.deliveries.last, /plain/).strip |
67 | 67 |
html_email_text = get_message_part(ActionMailer::Base.deliveries.last, /html/).strip |
@@ -72,4 +72,4 @@ describe Agents::DigestEmailAgent do |
||
72 | 72 |
@checker.reload.memory[:queue].should be_empty |
73 | 73 |
end |
74 | 74 |
end |
75 |
-end |
|
75 |
+end |